<template>
  <div>
    <el-table :data="cutObj.records" style="width: 100%;height:200px;">
      <el-table-column prop="name" label="供应商名称" width="300"/>
      <el-table-column prop="principal" label="负责人" width="300"/>
      <el-table-column prop="manage" label="经验范围" width="200"/>
      <el-table-column fixed="right" label="操作" width="250">
        <template #default="scope">
          <el-button type="primary" @click="find(scope.row.id)">查看</el-button>
          <el-button type="primary" @click="update(scope.row.id)">修改信息</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        v-model:page-size="cutObj.size"
        background
        :total="cutObj.total"
        @current-change="findByItem"
    />
    <div>
      <el-row>
        <el-col :span="5">供应商名称:<input type="text " v-model="findObj.name" style="width: 80px"></el-col>
        <el-col :span="5">经营范围:<input type="text " v-model="findObj.manage" style="width: 80px"></el-col>
        <el-col :span="7">
          <el-button type="primary" @click="findByItem(1)">搜素</el-button>
        </el-col>
      </el-row>
    </div>
    <!--  添加  -->

    <el-button type="primary" @click="add()">添加</el-button>

    <el-dialog
        v-model="addVisible"
        title=" 添加供应商信息"
        width="50%"
    >
      <el-form :label-position='"left"' label-width="100px" :model="supplierObj">
        <el-form-item label="供应商">
          <el-input type="text" v-model="supplierObj.name" style="width: 60%;"></el-input>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input type="text" v-model="supplierObj.principal" style="width: 60%;"></el-input>
        </el-form-item>
        <el-form-item label="负责人电话">
          <el-input type="text" v-model="supplierObj.phone" style="width: 60%;"></el-input>
        </el-form-item>
        <el-form-item label="供应商地址">
          <el-input type="text" v-model="supplierObj.address" style="width: 60%;"></el-input>
        </el-form-item>
        <el-form-item label="经营范围">
          <el-input type="textarea" v-model="supplierObj.manage" style="width: 60%;"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="addSupplier()">添加</el-button>
    </el-dialog>


    <!--修改-->
    <el-dialog
        v-model="updateVisible"
        title="修改供应商信息"
        width="30%"
    >
      <div>
        <el-form :label-position='"left"' label-width="100px" :model="supplier">
          <el-form-item label="供应商">
            {{ supplier.name }}
          </el-form-item>
          <el-form-item label="负责人">
            <el-input type="text" v-model="supplier.principal" style="width: 60%;"></el-input>
          </el-form-item>
          <el-form-item label="负责人电话">
            <el-input type="text" v-model="supplier.phone" style="width: 60%;"></el-input>
          </el-form-item>
          <el-form-item label="供应商地址">
            {{ supplier.address }}
          </el-form-item>
          <el-form-item label="经营范围">
            {{ supplier.manage }}
          </el-form-item>
          <el-button type="primary" @click="updateSupplier()">确定</el-button>
        </el-form>
      </div>
    </el-dialog>

    <!--  查看  -->
    <el-dialog
        v-model="supplierVisible"
        title="查看供应商信息"
        width="30%"
    >
      <div>
        <el-form :label-position='"left"' label-width="100px" :model="supplier">
          <el-form-item label="供应商">
            {{ supplier.name }}
          </el-form-item>
          <el-form-item label="负责人">
            {{supplier.principal}}
          </el-form-item>
          <el-form-item label="负责人电话">
           {{supplier.phone}}
          </el-form-item>
          <el-form-item label="供应商地址">
            {{ supplier.address }}
          </el-form-item>
          <el-form-item label="经营范围">
            {{ supplier.manage }}
          </el-form-item>
          <el-button type="primary" @click="supplierVisible = false">确定</el-button>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      findObj: {},
      cutObj: [],
      supplierVisible: false,
      supplier: {},
      updateVisible: false,
      addVisible: false,
      supplierObj: {}
    }
  },
  methods: {
    findByItem(pageNO) {
      this.findObj.pageNO = pageNO
      axios.get("/project/Supplier/findByItem", {params: this.findObj}).then(resp => {
        this.cutObj = resp.data
      })
    },
    find(id) {
      this.supplierVisible = true
      axios.get("/project/Supplier/findById", {params: {id: id}}).then(resp => {
        this.supplier = resp.data;
      })
    },
    add() {
      this.addVisible = true
    },
    addSupplier() {
      axios.get("/project/Supplier/add", {params: this.supplierObj}).then(resp => {
        if (resp.data == "ok") {
          this.addVisible = false
          this.findByItem(1);
        }
      })
    },
    update(id) {
      this.updateVisible = true
      axios.get("/project/Supplier/findById", {params: {id: id}}).then(resp => {
        this.supplier = resp.data;
      })
    },
    updateSupplier() {
      axios.get("/project/Supplier/update", {params: this.supplier}).then(resp => {
        if (resp.data == "ok") {
          this.updateVisible = false,
              this.findByItem(1);
        }
      })
    }
  },
  created() {
    this.findByItem(1)
  }

}
</script>

<style scoped>

</style>